package com.hs.telepass.controller.task;


import android.content.Intent;

import com.hs.telepass.controller.TaskController;
import com.hs.telepass.model.json.response.GetOrgInfoResponseJson;
import com.hs.telepass.utils.JsonUtil;

public class GetOrgInfoTask extends Task {
    public final static String ACTION_GET_ORG_INFO = "action_get_org_info";

    private String jsonRequstStr;
    private String taskUrl;
    private int requestType;

    public GetOrgInfoTask(String meeting_id) {
        jsonRequstStr = "meeting_id=" + meeting_id;
        requestType = TASK_REQUST_TYPE_POST;
        taskUrl = BASE_ORG_API_URL + "/" + "ApiPairUser/getOrgInfo";
    }

    @Override
    public void onExecuted(String response, int httpCode) {
        Intent intent = new Intent(getActionName());

        GetOrgInfoResponseJson json = JsonUtil.fromJson(response, GetOrgInfoResponseJson.class);

        int status = json.getStatus();
        if (0 != status) {
            intent.putExtra(TaskController.EXTRA_EVENT, TaskController.EVENT_TASK_ERROR);
            intent.putExtra(TaskController.EXTRA_RESPONSE, "服务器返回" + status + "状态码");
        }else{
            intent.putExtra(TaskController.EXTRA_EVENT, TaskController.EVENT_TASK_SUCCEED);
            intent.putExtra(TaskController.EXTRA_RESPONSE, json);
        }


        broadcastManager.sendBroadcast(intent);
    }

    @Override
    public int getRequstType() {
        return requestType;
    }

    @Override
    public String getJsonRequstStr() {
        return jsonRequstStr;
    }

    @Override
    public int getResponseSuccessCode() {
        return 0;
    }

    @Override
    public String getTaskUrl() {
        return taskUrl;
    }

    @Override
    public String getActionName() {
        return ACTION_GET_ORG_INFO;
    }
}
